import socket


HOST = '127.0.0.1'
PORT = 12346
ADDR = (HOST, PORT)

udp_client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)   # 创建套接字
while True:
    data = input('>').encode('utf-8')
    if not data:
        break
    udp_client.sendto(data, ADDR)   # 发送数据
    recv_data, recv_addr = udp_client.recvfrom(1024)    # 接收数据
    if not recv_data:
        break
    print(recv_data.decode('utf-8'))

udp_client.close()
